from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
# 创建分页器类
class ProductPageNumberPagination(PageNumberPagination):
    page_size = 10 # 默认页面数据量为10条
    page_query_param = 'page' # 当前页的参数名
    page_size_query_param = "size" # 每页显示条数的参数名
    max_page_size = 100

    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'data': data,
        })